package cn.vin.ws;

import org.apache.commons.lang3.RandomUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class ClientEngineCldld {
//    static String urlStr = "ws://localhost:7110/websocket7110";
//    static String urlStr = "ws://120.27.250.213:7100/websocket";
//    static String urlStr = "wss://xyx2.17tcw.com:7100/websocket";
//    static String urlStr = "ws://47.88.170.168:7110/websocket7110";
//    static String urlStr = "ws://47.74.191.242:7120/websocket7120";
//    static String urlStr = "ws://47.74.191.242:7130/websocket7130";
//    static String urlStr = "wss://xyx-sg-ng.ihago.net/conglindaluandou_yn/websocket";
    static String urlStr = "wss://xyx-sg-ng.ihago.net/conglindaluandou_yn/websocket7140";
//    static String urlStr = "wss://conglin.17tcw.com:8120/websocket";
//    static String loginMsg = "{\"cmd\":2001,\"openid\":\"test4\",\"reqLogin\":{\"icon\":\"http://123\",\"name\":\"ะกอ๕\",\"curRole\":[1,2,3],\"wincount\":5,\"totalcount\":0,\"pillarMin\":1,\"pillarMax\":1,\"losecount\":2,\"levelId\":1,\"score\":%d,\"roleType\":0,\"gold\":%d,\"roleType\":%d, \"version\":100}}";
    static String loginMsg = "{\"cmd\":2001,\"openid\":\"test4\",\"reqLogin\":{\"icon\":\"http://123\",\"name\":\"ะกอ๕\",\"curRole\":[1,2,3],\"wincount\":5,\"totalcount\":0,\"pillarMin\":1,\"pillarMax\":1,\"losecount\":2,\"levelId\":1,\"score\":%d,\"roleType\":0,\"gold\":%d,\"roleType\":%d, \"version\":100}}";
    static String ready = "{\"cmd\":2015,\"openid\":\"test4\",\"reqReady\":{\"icon\":\"http://123\",\"name\":\"ะกอ๕\",\"curRole\":[1,2,3],\"wincount\":5,\"totalcount\":0,\"pillarMin\":1,\"pillarMax\":1,\"losecount\":2,\"levelId\":1,\"roleType\":0, \"version\":100}}";
    static String reset = "{\"cmd\":2018,\"openid\":\"test4\",\"reqResetConnectionState\":{\"icon\":\"http://123\",\"name\":\"ะกอ๕\",\"curRole\":[1,2,3],\"wincount\":5,\"totalcount\":0,\"pillarMin\":1,\"pillarMax\":1,\"losecount\":2,\"levelId\":1,\"roleType\":0, \"version\":100}}";
    static String achieve = "{\"cmd\":2004,\"openid\":\"test4\",\"reqAchieve\":{\"scoreA\":3, \"scoreB\":0}}";
    static String reflight = "{\"cmd\":2008,\"openid\":\"test4\",\"reqReFight\":{}}";
    public static void main(String[] args) throws Exception {
        MsgWebSocketClient c = new MsgWebSocketClient("test4",urlStr);
        c.score = RandomUtils.nextInt(50,20000);
        c.gold = (long)Integer.MAX_VALUE + 100000;
        c.connect();

        Thread.sleep(2000);


        while(true) {
            System.out.println("输入指令");
            Scanner sc = new Scanner(System.in);
            int cmd = sc.nextInt();
            switch (cmd) {
                case 2001:
                    c.send(String.format(loginMsg,c.score,c.gold,RandomUtils.nextInt(0,2)));
                    break;
                case 2015:
                    c.send(ready);
                    break;
                case 2018:
                    c.send(reset);
                    break;
                case 2004:
                    c.send(achieve);
                    break;
                case 2008:
                    c.send(reflight);
                    break;

            }
        }
    }
}
